<template>
    <div class="mui-content" style="margin-top: -15px">
        <form class="mui-input-group">
            <div class="mui-input-row">
                <label>原密码</label>
                <input id="account" type="text" class="mui-input-clear mui-input" placeholder="请输入原密码" data-input-clear="1" v-model="originPassword"><span class="mui-icon mui-icon-clear mui-hidden"></span>
            </div>
            <div class="mui-input-row">
                <label>新密码</label>
                <input id="password" type="password" class="mui-input-clear mui-input" placeholder="请输入新密码" data-input-clear="2" v-model="nowPassword"><span class="mui-icon mui-icon-clear mui-hidden"></span>
            </div>
            <div class="mui-input-row">
                <label>确认密码</label>
                <input id="password_confirm" type="password" class="mui-input-clear mui-input" placeholder="请确认密码" data-input-clear="3" v-model="repeatPassword"><span class="mui-icon mui-icon-clear mui-hidden"></span>
            </div>
        </form>
        <div class="mui-content-padded">
            <button id="reg" class="mui-btn mui-btn-block mui-btn-primary" @click="editPassword">修改密码</button>
        </div>

    </div>
</template>

<script>
    import { Toast } from 'mint-ui'
    export default {
        data() {
            return {
                originPassword: '',
                nowPassword: '',
                repeatPassword: '',
                id: this.$route.params.id
            }
        },
        methods: {
            editPassword() {
                this.$http.get('http://127.0.0.1:3002/getInfo?id='+this.id).then((result) => {
                    if(result.body.status == 0){
                        if(result.body.message[0].password ==this.originPassword&&this.nowPassword == this.repeatPassword){
                            this.$http.get('http://127.0.0.1:3002/editpwd?pwd='+this.nowPassword+"&id="+this.id).then((result)=>{
                                Toast(result.body.message);
                                this.$router.push('/user')
                            });
                        }
                        else if(result.body.message[0].password !=this.originPassword){
                            Toast('请输入正确的原密码');
                        }
                        else if(this.nowPassword != this.repeatPassword){
                            Toast('密码不一致');
                        }
                    }else{
                        Toast('网络抽风了');
                    }
                })

            }
        }
    }
</script>

<style scoped>

</style>